/*
 * @Description: 3d相关
 * @Date: 2022-03-17 10:07:11
 * @Author: yeming
 */

// 默认蓝色区域
const DEFAULT_CIRCLE_STYLE = { 'fillColor': 'rgba(0, 153, 255, 0.1)', 'strokeColor': 'rgba(0, 153, 255, 1)', 'strokeWidth': 2 }
// 绿色区域
const GREEN_CIRCLE_STYLE = { 'fillColor': '#00666688', 'strokeColor': 'green', 'strokeWidth': 2 }

export var CesiumCircle = (function () {
  function _ (entities, id, type, latlng, radius, style, clampToGround) {
    let customStyle = {}
    if (style === null || JSON.stringify(style) == "{}") {
      if (type === 4) customStyle = GREEN_CIRCLE_STYLE // 吊舱视野点位置
      else customStyle = DEFAULT_CIRCLE_STYLE
    } else customStyle = style

    this.options = {
      id: id, // 创建和2d飞机相同sn的entity,
      name: 'Circle3d_' + id,
      type: type,
      show: true,
      ellipse: {
        material: Cesium.Color.fromCssColorString(customStyle.fillColor).withAlpha(0.1),
        semiMinorAxis: radius,
        semiMajorAxis: radius,
        clampToGround: clampToGround,
        height: latlng[2] || 80,
        // extrudedHeight: extrudedHeight,
        outline: true,
        outlineColor: Cesium.Color.fromCssColorString(customStyle.strokeColor),
        outlineWidth: customStyle.strokeWidth
      }
    };
    this.entities = entities;
    this._init(latlng);
  }
  _.prototype._init = function (latlng) {
    var _self = this;
    var _update = function () {
      return _self.position;
    };
    this.options.position = new Cesium.CallbackProperty(_update, false);
    this.entity = this.entities.add(this.options);
    //this.position= new Cesium.Cartesian3.fromDegrees(latlng[0], latlng[1]);
  };
  _.prototype.setRadius = function (radius) {
    this.entity.ellipse.semiMinorAxis = radius
    this.entity.ellipse.semiMajorAxis = radius
  }
  _.prototype.setPosition = function (llWGS84) {
    this.entity.ellipse.height = llWGS84[2] == null ? 0 : llWGS84[2];
    //console.log("setposlatlng", llWGS84)
    this.position = new Cesium.Cartesian3.fromDegrees(llWGS84[0], llWGS84[1]);
  }
  _.prototype.Dispose = function () {
    this.entities.remove(this.entity);
    this.entity = null;
  }
  return _;
})();